﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        string memberLogin = txtUser.Text.Trim();
        string password = txtPassword.Text.Trim();
        BookStoreDataContext bs = new BookStoreDataContext();
        var users = (from u in bs.members where u.member_login == memberLogin && u.member_password == password select u );
        if (users.Count<member>() > 0)
        {
            FormsAuthentication.SetAuthCookie(memberLogin, true);
            Session["login"] = memberLogin;
        }
        else {
            lblLoginMessage.Visible = true;
        }
        if (FormsAuthentication.GetRedirectUrl(memberLogin, true) != null)
        {
            Response.Redirect(FormsAuthentication.GetRedirectUrl(memberLogin, true));
        }
        else {
            Response.Redirect("default.aspx");
        }
    }
}